# -*- coding: utf-8 -*-
# filename: main.py
import web
import hashlib

urls = (
    '/wx', 'Handle',
)

class Handle(object):
    def GET(self):
        try:
            data=web.input()
            if len(data)==0:
                return "Bad token request!"
            signature=data.signature
            timestamp=data.timestamp
            nonce=data.nonce
            echost=data.echostr
            token="maolala"

            listArray=[token,timestamp,nonce]
            listArray.sort()
            sha1=hashlib.sha1()
            valueMap=map(sha1.update,listArray)
            hashCode=sha1.hexdigest()
            print "handler/GET func:hashcode,signature",hashcode,signature
            if hashCode==signature:
                return echostr
            else:
                return ""
        except Exception,Argument:
            return Argument

if __name__ == '__main__':
    app = web.application(urls, globals())
    app.run()
